var uid, ws;
document.addEventListener('plusready', function(){
	ws = plus.webview.currentWebview();
	uid = plus.storage.getItem('uid');
	console.log(uid);
	//加载我的药品列表
	showWating();
	Me_drug();
}, false)
function Me_drug(){
	$.ajax({
		type:"get",
		url:apiRoot+"/home/medicinal/MedicineList",
		data :{
			uid :uid
		},
		dataType :'json',
		success :function(data){
			plus.nativeUI.closeWaiting();
//			console.log(JSON.stringify(data));
			if(data.length > 0){
				var list = '';
				$.each(data, function(k, v) {
//					console.log(JSON.stringify(v));
					list += '<ul class="mui-table-view OA_task_1" aid="'+v.aid+'">'+
						'<li class="mui-table-view-cell frien_img">'+
							'<div class="mui-slider-right mui-disabled">'+
								'<a class="mui-btn mui-btn-red">下架</a>'+
							'</div>'+
							'<div class="mui-slider-handle mui-table" tid="'+v.tid+'" aid="'+v.aid+'">'+
								'<div class="home_top">'+
									'<img src="'+getAvatar(v.litpic)+'"/>'+
								'</div>'+
								'<div class="frien_bq">'+
									'<h5 class="mui-ellipsis-2">'+v.title+'</h5>'+
								'</div>'+
							'</div>'+
						'</li>'+
					'</ul>';
				});
				$('.Drug').html(list);
				//进入药品详情
				$('.mui-table').on('tap', function(){
					var tid = $(this).attr('tid');
					var aid = $(this).attr('aid');
//					var str = tid == '2' ? 'Chinese_medicine.html' : 'West_medicine.html';
					console.log(tid+" "+aid);
					goNewPage('shop-information.html', {spage:ws.id, aid:aid, type:tid});
				})
				//下架
				$('.mui-disabled').on('tap', function(){
					var _this = $(this);
					var pid = _this.parent().parent().attr('aid');
					console.log(pid);
					plus.nativeUI.confirm('确认下架改商品吗？', function(e){
						if(e.index == 1){
							showWating();
							$.ajax({
								type:"get",
								url:apiRoot+"/home/medicinal/offSale",
								data :{pid:pid},
								success :function(data){
									plus.nativeUI.closeWaiting();
									console.log(data);
									if(data > 0){
										toast('下架成功');
										_this.parent().parent().remove();
									}
								},
								error :function(e){
									errortoast();
									console.log(JSON.stringify(e));
								}
							});
						}
					}, null, ['取消', '确认'])
				})
			}
		},
		error :function(e){
			errortoast();
			console.log(JSON.stringify(e));
		}
	});
}
